<?php
function fungsi($file) {
	require_once ABSPATH.'functions/func.'.$file.'.php';
}

function jumlah_user() {
	return mysql_num_rows(mysql_query("SELECT a.*,b.nm_lengkap,c.nm_jabatan FROM t_pengguna a
										inner join t_pegawai b on a.kd_pengguna=b.kd_pengguna
										inner join r_jabatan c on c.kd_jabatan=b.kd_jabatan
										where a.jns_pengguna <> 'admin' and a.jns_pengguna <> 'superadmin'"));
}


function jumlah_data($tabel) {
	return mysql_num_rows(mysql_query("SELECT * FROM t_".$tabel));
}

function jumlah_pemberitahuan($kd_pengguna) {
	return mysql_num_rows(mysql_query("SELECT kd_pegawai FROM t_pemberitahuan WHERE terbaca='t' AND kd_pegawai=".$kd_pengguna));
}

function jumlah_info($kd_pengguna) {
			if(LEVEL=="superadmin" || LEVEL=="admin") {
				$q = mysql_query("SELECT * FROM t_pemberitahuan WHERE terbaca='t' and isnull(kd_pegawai) order by waktu ");
			} else if(ID_PEGAWAI==""){
				$q = mysql_query("SELECT * FROM t_pemberitahuan WHERE terbaca='t' AND kd_pengguna='".ID."' order by waktu");
			}else{
				$q = mysql_query("SELECT * FROM t_pemberitahuan WHERE terbaca='t' AND kd_pegawai='".ID_PEGAWAI."' order by waktu");
			}							
								
	return mysql_num_rows($q);
}

function jumlah_info_all() {
	return mysql_num_rows(mysql_query("SELECT * FROM t_pemberitahuan WHERE terbaca='t' and isnull(kd_pegawai)"));
}

function jumlah_pesan($kd_pengguna) {
	return mysql_num_rows(mysql_query("SELECT kd_pesan FROM t_pesan WHERE terbaca='t' AND  kd_pengguna=".$kd_pengguna));
}

function kelamin($kd) {
	if($kd=="L") {
		echo "Laki-laki";
	} else {
		echo "Perempuan";
	}
}

function koneksi_buka() {
	mysql_select_db(DB_NAMA,mysql_connect(DB_HOST,DB_USER,DB_PASSWORD));
}

function koneksi_tutup() {
	mysql_close(mysql_connect(DB_HOST,DB_USER,DB_PASSWORD));
}

function konversi_tanggal($format, $tanggal) {
	$en=array("Sun","Mon","Tue","Wed","Thu","Fri","Sat","Jan","Feb",
	"Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	$id=array("Minggu","Senin","Selasa","Rabu","Kamis","Jumat","Sabtu",
	"Januari","Pebruari","Maret","April","Mei","Juni","Juli","Agustus","September",
	"Oktober","November","Desember");
	return str_replace($en,$id,date($format,strtotime($tanggal)));
}

function konversi_bulan($month) {
	$month = $month-1;
	$bulan=array("Januari","Pebruari","Maret","April","Mei","Juni","Juli","Agustus","September",
	"Oktober","November","Desember");
	return $bulan[$month];
}

function loncat($url) {
	header("Location:".$url);
}

function nip($teks) {
	$nip = trim($teks," ");
	$panjang = strlen($nip);
	if($panjang == 15) {
		$lahir		= substr($nip,0,8);
		$lantik		= substr($nip,8,6);
		$kelamin	= substr($nip,14,1);
		
		return $lahir." ".$lantik." ".$kelamin;
	} else if($panjang == 18) {
		$lahir		= substr($nip,0,8);
		$lantik		= substr($nip,8,6);
		$kelamin	= substr($nip,14,1);
		$urut		= substr($nip,15,3);
		
		return $lahir." ".$lantik." ".$kelamin." ".$urut;
	} else {
		return $nip;
	}
}

function panggil_header() {
	require_once 'header.php';
}

function panggil_footer() {
	require_once 'footer.php';
}

function pengaturan($kunci, $kolom = 0) {
	$dt = mysql_fetch_array(mysql_query("SELECT nilai, keterangan FROM t_pengaturan WHERE kunci='".$kunci."'"));
	return $dt[$kolom];
}

function tab_aktif($p, $page, $url, $default = false, $tambah = false) {
	if(($default && $p=="") || $p==$page) { echo 'class="btn disabled"'; } 
	else { echo 'href="'.$url.'" class="btn"'; }
}

function cek_collapse($is_collapse){
	if(!$is_collapse){
		echo 'class="da-panel collapsible collapsed"';
	}else{
		echo 'class="da-panel collapsible"';
	}
}
?>
